package com.wry.wry_test.algorithm;

import javax.crypto.Cipher;
import java.util.*;

public class Day07 {
    public static int solution(int[] numbers) {
        // Please write your code here
        List<List<Integer>> nums = new ArrayList<>(numbers.length);
        for (int number : numbers) {
            List<Integer> list = new ArrayList<>();
            while (number > 0) {
                list.add(number % 10);
                number /= 10;
            }
            nums.add(list);
        }
        Set<Integer> numSet = new HashSet<>();
        cal("", nums, 0, numSet, 0);

        return numSet.size();
    }

    private static void cal(String num, List<List<Integer>> nums, int index, Set<Integer> numSet, int sum) {
        if (index >= nums.size()) {
            if (sum % 2 == 0) {
                numSet.add(Integer.parseInt(num));
            }
        } else {
            List<Integer> list = nums.get(index);
            for (Integer i : list) {
                cal(num + i, nums, index + 1, numSet, sum + i);
            }
        }
    }


    public static void main(String[] args) {
        // You can add more test cases here
        System.out.println(solution(new int[]{123, 456, 789}) == 14);
        System.out.println(solution(new int[]{123456789}) == 4);
        System.out.println(solution(new int[]{14329, 7568}) == 10);
    }
}
